//
//  SRSportNetSource.m
//  SportRing
//
//  Created by Apple on 14/10/29.
//  Copyright (c) 2014年 HotOne. All rights reserved.
//

#import "SRSportNetSource.h"
#import <HealthKit/HealthKit.h>

@implementation SRSportNetSource

//上传计步数据
+ (void)addRecordCounterWithToken:(NSString *)token
                          section:(int)section
                       runCounter:(int)runCounter
                  upstairsCounter:(int)upstairsCounter
                      walkCounter:(int)walkCounter
                          calorie:(int)calorie
                               T1:(int)T1
                               T2:(int)T2
                               T3:(int)T3
                               T4:(int)T4
                          mileage:(int)mileage
                       createDate:(NSString *)createDate
                          success:(CompletionBlockWithDictionary)success
                          failure:(CompletionBlockWithError)failure
{
    NSDictionary * dict = @{@"section":@(section),
                            @"runCounter":@(runCounter),
                            @"upstairsCounter":@(upstairsCounter),
                            @"walkCounter":@(walkCounter),
                            @"calorie":@(calorie),
//                            @"T1":@(T1),
//                            @"T2":@(T2),
//                            @"T3":@(T3),
//                            @"T4":@(T4),
                            @"mileage":@(mileage)};
    
    [self postAction:@"v1/counter/addrecord"
          parameters:@{@"token":token,@"createDate":createDate,@"counter":@[dict]}
             success:success
             failure:failure];
}

//获取月步计数统计
+ (void)getStatisticsByMonthCounterWithToken:(NSString *)token
                                       month:(NSString *)month
                                     success:(CompletionBlockWithDictionary)success
                                     failure:(CompletionBlockWithError)failure
{
    [self postAction:@"v1/Counter/GetStatisticsByMonth"
          parameters:@{@"token":token, @"month":month}
             success:success
             failure:failure];
}

//获取指定月的每天数据
+ (void)getDaySportForMonthWithToken:(NSString *)token
                              yyyyMM:(NSString *)yyyyMM
                             success:(CompletionBlockWithDictionary)success
                             failure:(CompletionBlockWithError)failure
{
    [self postAction:@"v1/counter/getrecords"
          parameters:@{@"token":token, @"startDate":yyyyMM}
             success:success
             failure:failure];
}

//获取天计步数据
+ (void)getRecordByDateCounterWithToken:(NSString *)token
                                   date:(NSString *)date
                                success:(CompletionBlockWithArray)success
                                failure:(CompletionBlockWithError)failure
{
    [self postAction:@"v1/Counter/GetRecord"
          parameters:@{@"token":token, @"date":date}
            success:success
            failure:failure];
}

//上传计步任务数据
+ (void)addTaskWithToken:(NSString *)token
              createDate:(NSString *)createDate
               startTime:(NSString *)startTime
                 endTime:(NSString * )endTime
            totalCounter:(int)totalCounter
        completedCounter:(int)completedCounter
                 success:(CompletionBlockWithDictionary)success
                 failure:(CompletionBlockWithError)failure
{
    [self postAction:@"v1/Task/AddTask"
          parameters:@{@"token":token,
                       @"createDate":createDate,
                       @"startTime":startTime,
                       @"endTime":endTime,
                       @"totalCounter":@(totalCounter),
                       @"completedCounter":@(completedCounter),}
             success:success
             failure:failure];
}

//获取月计步任务统计
+ (void)getTaskStatisticsWithToken:(NSString *)token
                             month:(NSString *)month
                           success:(CompletionBlockWithDictionary)success
                           failure:(CompletionBlockWithError)failure
{
    [self postAction:@"v1/Task/GetStatisticsByMonth"
          parameters:@{@"token":token, @"month":month}
            success:success
            failure:failure];
}

//获取天计步任务数据
+ (void)getTaskByDayWithToken:(NSString *)token
                         date:(NSString *)date
                      success:(CompletionBlockWithDictionary)success
                      failure:(CompletionBlockWithError)failure
{
    [self postAction:@"v1/Task/GetTask"
          parameters:@{@"token":token, @"date":date}
            success:success
            failure:failure];
}

+ (void)getTasksByDayWithToken:(NSString *)token
                     startDate:(NSString *)startDate
                       endDate:(NSString *)endDate
                       success:(CompletionBlockWithDictionary)success
                       failure:(CompletionBlockWithError)failure
{
    [self postAction:@"v1/Task/GetTask"
          parameters:@{@"token":token, @"date":startDate}
             success:success
             failure:failure];
}

//上传睡眠数据
+ (void)uploadSleepWithToken:(NSString *)token
                   startTime:(NSString *)startTime
                     endTime:(NSString *)endTime
                      sleeps:(NSArray *)sleeps
                     success:(CompletionBlockWithDictionary)success
                     failure:(CompletionBlockWithError)failure
{
    NSMutableDictionary * params = [@{@"token":token, @"count":sleeps} mutableCopy];
    if (startTime) {
        params[@"startTime"] = startTime;
    }
    if (endTime) {
        params[@"endTime"] = endTime;
    }
    [self postAction:@"v1/Sleep/AddRecord"
          parameters:params
             success:success
             failure:failure];
}

//获取天睡眠数据
+ (void)getRecordSleepWithToken:(NSString *)token
                           date:(NSString *)date
                        success:(CompletionBlockWithDictionary)success
                        failure:(CompletionBlockWithError)failure

{
    [self postAction:@"v1/Sleep/GetRecord"
          parameters:@{@"token":token, @"date":date}
             success:success
             failure:failure];
}

//睡眠评估
+ (void)evaluateSleepWithToken:(NSString *)token
                      duration:(int)duration
                          rems:(int)rems
                         nrems:(int)nrems
                        wakeup:(int)wakeup
                       success:(CompletionBlockWithDictionary)success
                       failure:(CompletionBlockWithError)failure
{
    [self postAction:@"v1/Sleep/evaluate"
          parameters:@{@"token":token,
                       @"duration":@(duration),
                       @"rems":@(rems),
                       @"nrems":@(nrems),
                       @"wakeup":@(wakeup)}
             success:success
             failure:failure];
}

//运动评估
+ (void)evaluateCounterWithToken:(NSString *)token
                         counter:(int)counter
                         mileage:(int)mileage
                         calorie:(int)calorie
                         success:(CompletionBlockWithDictionary)success
                         failure:(CompletionBlockWithError)failure
{
    [self postAction:@"v1/Counter/evaluate"
          parameters:@{@"token":token,
                       @"counter":@(counter),
                       @"mileage":@(mileage),
                       @"calorie":@(calorie)}
             success:success
             failure:failure];
}


@end
